import java.util.HashMap;
import java.util.Map;

public class Difference {

    public static int getDifference(int[] arr, int difference){
        int res=0;
        Map<Integer,Integer> temp=new HashMap<>();
        for (int i = 0; i < arr.length; i++) {
            temp.put(arr[i],temp.getOrDefault(arr[i]-difference,0)+1);
            res=Math.max(res,temp.get(arr[i]));
        }
        return res;
    }

    public static void main(String[] args) {
        int[] a={1,2,3,4,5};
        getDifference(a,1);
    }
}
